from src.core.models.dto import (
    CalendarDTO,
    CalendarTaskDTO,
    CalendarWithTasksAndMessagesDTO,
    CheckMessageDTO,
    UserCalendarDTO,
)
from src.database.models import Calendar, CalendarTask, CheckMessage, UserCalendar


def convert_db_model_to_calendar_dto(calendar: Calendar) -> CalendarDTO:
    return CalendarDTO(
        id=calendar.id,
        title_ru=calendar.title_ru,
        title_en=calendar.title_en,
        title_uk=calendar.title_uk,
        description_ru=calendar.description_ru,
        description_en=calendar.description_en,
        description_uk=calendar.description_uk,
        final_message_ru=calendar.final_message_ru,
        final_message_en=calendar.final_message_en,
        final_message_uk=calendar.final_message_uk,
        category_id=calendar.category_id,
    )


def convert_db_model_to_calendar_task_dto(task: CalendarTask) -> CalendarTaskDTO:
    return CalendarTaskDTO(
        id=task.id,
        day=task.day,
        task_text_ru=task.task_text_ru,
        task_text_en=task.task_text_en,
        task_text_uk=task.task_text_uk,
        media_filename=task.media_filename,
    )


def convert_db_model_to_check_message_task_dto(
    message: CheckMessage,
) -> CheckMessageDTO:
    return CheckMessageDTO(
        id=message.id,
        text_ru=message.text_ru,
        text_en=message.text_en,
        text_uk=message.text_uk,
        media_filename=message.media_filename,
    )


def convert_db_model_to_calendar_with_tasks_and_messages_dto(
    calendar: Calendar,
) -> CalendarWithTasksAndMessagesDTO:
    tasks = [convert_db_model_to_calendar_task_dto(task) for task in calendar.tasks]
    check_messages = [
        convert_db_model_to_check_message_task_dto(message)
        for message in calendar.check_messages
    ]
    return CalendarWithTasksAndMessagesDTO(
        id=calendar.id,
        title_ru=calendar.title_ru,
        title_en=calendar.title_en,
        title_uk=calendar.title_uk,
        description_ru=calendar.description_ru,
        description_en=calendar.description_en,
        description_uk=calendar.description_uk,
        final_message_ru=calendar.final_message_ru,
        final_message_en=calendar.final_message_en,
        final_message_uk=calendar.final_message_uk,
        category_id=calendar.category_id,
        tasks=tasks,
        check_messages=check_messages,
    )


def convert_db_model_to_user_calendar_dto(
    user_calendar: UserCalendar,
) -> UserCalendarDTO:
    calendar = user_calendar.calendar
    return UserCalendarDTO(
        id=user_calendar.id,
        status=user_calendar.status,
        title_ru=calendar.title_ru,
        title_en=calendar.title_en,
        title_uk=calendar.title_uk,
        description_ru=calendar.description_ru,
        description_en=calendar.description_en,
        description_uk=calendar.description_uk,
        final_message_ru=calendar.final_message_ru,
        final_message_en=calendar.final_message_en,
        final_message_uk=calendar.final_message_uk,
        category_id=calendar.category_id,
        user_id=user_calendar.user_id,
        calendar_id=user_calendar.calendar_id,
        subscription_id=user_calendar.subscription_id,
        successful_tasks=user_calendar.successful_tasks,
        tasks_sent=user_calendar.tasks_sent,
        get_tasks_time=user_calendar.get_tasks_time,
        check_tasks_time=user_calendar.check_tasks_time,
    )
